#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int N = 1e5 + 10;
int sum[N], f[N], g[N];
int main() {
    int n = 0, x = 0;
    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> x;
        sum[x] += x;
    }
    f[0] = sum[0], g[0] = 0;
    for (int i = 1; i < N; i++)
    {
        f[i] = g[i - 1] + sum[i];
        g[i] = max(f[i - 1], g[i - 1]);
    }

    cout << max(f[N - 1], g[N - 1]);


}